using System;
using System.Collections.Generic;
using System.Text;

namespace CoastToCoast.Game {
    public abstract class Unit : Entity {
        private Player _owner;
        public Player Owner {
            get { return _owner; }
            set { _owner = value; }
        }

        private int _currentHP;
        public int CurrentHP {
            get { return _currentHP; }
            set { _currentHP = value; }
        }

        private int _currentMoves;
        public int CurrentMoves {
            get { return _currentMoves; }
            set { _currentMoves = value; }
        }

        public abstract int BaseHealth {
            get;
        }

        public abstract int BaseMovementRate {
            get;
        }

        public abstract int BaseAttackDamage {
            get;
        }

        public abstract int BaseProductionCost {
            get;
        }

        // Basically calls UnitFactory.Create<Type> with the right type/owner
        public abstract Unit Create(Player owner);

        // REVIEW: Returns false if move is illegal, all moves are one step at a time??
        public abstract bool CanMove(Cell destination);
        public void Move(Cell destination) {
            // REVIEW: Assume can move has been called?
            if (CanMove(destination)) {
                //unit.CurrentMoves++;
                destination.Board.Move(this, destination);
            }
        }

        private EventHandler _death;
        public event EventHandler Death {
            add {
                _death = (EventHandler)Delegate.Combine(_death, value);
            }
            remove {
                if (_death != null) {
                    _death = (EventHandler)Delegate.Remove(_death, value);
                }
            }
        }

        public virtual void Die(EventArgs args) {
            if (_death != null) {
                _death(this, args);
            }

            // clean up
            Cell = null;
            Owner.RemoveUnit(this);
        }

        public virtual void OnStartTurn(object sender, EventArgs args) {
            _currentMoves = 0;
            // adjust HP?
        }
    }
}
